<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>结算操作页面</title>
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <!--<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">-->
    <style>
        .layui-form-label {
            width: 100px;
        }
        .layui-form-item {
            margin-top: 10px;
        }
    </style>
</head>
<body>
<input id="hidValue" type="hidden">
<form class="layui-form" id="editForm" style="padding-top: 15px;padding-right: 15px">
    <input id="cbpid" name="cbpid" type="hidden">
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">业务名称<span style="color: red;">*</span></label>
        <div class="layui-inline">
            <input id="type" name="type" class="layui-input" type="text" lay-verify="required"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">最高代收货款(元)<span style="color: red;">*</span></label>
        <div class="layui-inline">
            <input id="maximumPayment" name="maximumPayment" class="layui-input" type="text" lay-verify="number"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">手续费(%)<span style="color: red;">*</span></label>
        <div class="layui-inline">
            <input id="commisionRateRuling" name="commisionRateRuling" class="layui-input" type="text" lay-verify="number"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">最低手续费(元)<span style="color: red;">*</span></label>
        <div class="layui-inline">
            <input id="minCommisionReceivable" name="minCommisionReceivable" class="layui-input" type="text" placeholder="请输入" lay-verify="number"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">最高手续费(元)<span style="color: red;">*</span></label>
        <div class="layui-inline">
            <input id="maxCommisionReceivable" name="maxCommisionReceivable" class="layui-input" type="text" placeholder="请输入" lay-verify="number"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">返款时间(小时)<span style="color: red;">*</span></label>
        <div class="layui-inline">
            <input id="deadline" name="deadline" class="layui-input" type="text" placeholder="请输入" lay-verify="number"/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">说明：</label>
        <div class="layui-input-block">
            <textarea id="describe" name="describe" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item text-right" style="margin-top: 20px;text-align: center;">
            <button class="layui-btn" lay-filter="editSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" id="closebutton" type="button" >取消</button>
    </div>
</form>
<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    // 要使用的layui模块
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer; // 获得layer模块
        var form = layui.form; // 获得form模块
        var $ = layui.$; // 调用JQuery方法时

        // 表单赋值
        var editdata = JSON.parse($("#hidValue").val());
        $('#cbpid').val(editdata.cbpid);
        $('#type').val(editdata.type);
        $('#maximumPayment').val(editdata.maximumPayment);
        $('#commisionRateRuling').val((editdata.commisionRateRuling)*100);
        $('#minCommisionReceivable').val(editdata.minCommisionReceivable);
        $('#maxCommisionReceivable').val((editdata.maxCommisionReceivable));
        $('#deadline').val(editdata.deadline);
        $('#describe').val(editdata.describe);

        // 监听关闭
        $('#closebutton').click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        })


        form.on('submit(editSubmit)', function(data){
            layer.confirm('是否提交？', {
                btn: ['是','否'] //按钮
            }, function(){
                // $("#changeForm").submit();//重点一！！！模拟提交！！
                var index = parent.layer.getFrameIndex(window.name);

                // alert(JSON.stringify(data.field.goodsBillCode));
                // alert(data.field.goodsBillCode);

                console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                $.ajax({
                    url: '/application/business/collection/edit',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        "cbpid": data.field.cbpid,
                        "type": data.field.type,
                        "maximumPayment": data.field.maximumPayment,
                        "commisionRateRuling": data.field.commisionRateRuling,
                        "minCommisionReceivable": data.field.minCommisionReceivable,
                        "maxCommisionReceivable": data.field.maxCommisionReceivable,
                        "deadline": data.field.deadline,
                        "describe": data.field.describe
                    },
                    success: function(result) {
                        if(result.msg.indexOf("成功") == -1){
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1500
                            });
                        }else{
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1500
                            });
                            setTimeout(function() {
                                /* 关闭弹出层 */
                                parent.layer.close(index);
                                /* 刷新父页面中的表格 */
                                parent.layui.table.reload('collectionTable');
                                /* 刷新父页面 */
                                // parent.location.reload();
                            }, 2000);
                        }
                    }
                });
            }, function(){
                layer.msg('已取消..');
                return false;
            });
            return false;//重点二！！！！  阻止提交行为！！
        });

        // 监听提交
        // form.on('submit(editSubmit)', function(data) {
        //
        // });
    });
</script>
</body>
</html>